import { Component, OnInit, Input, SimpleChange } from '@angular/core';
import { AuthUtilsService } from '@common/utils/auth.utils';
import { DashboardDetailsService } from '@routes/dashboard/thread-services/dashboard-details.service';
import { DashboardService } from '@services/dashboard.service';
import { MapConstant } from '@common/constants/map.constant';
import { GlobalVariable } from '@common/variables/global.variable';

@Component({
  selector: 'app-vulnerability-instruction',
  templateUrl: './vulnerability-instruction.component.html',
  styleUrls: ['./vulnerability-instruction.component.scss'],
})
export class VulnerabilityInstructionComponent implements OnInit {
  isAutoScanAuthorized!: boolean;
  isAutoScanOn!: boolean;
  get isRemote() {
    return GlobalVariable.isRemote;
  }

  constructor(
    private authUtilsService: AuthUtilsService,
    public dashboardDetailsService: DashboardDetailsService,
    private dashboardService: DashboardService
  ) {}

  ngOnInit(): void {
    this.isAutoScanAuthorized =
      this.authUtilsService.getDisplayFlag('runtime_scan') &&
      !this.authUtilsService.userPermission.isNamespaceUser;
  }

  turnOnAutoScan = () => {
    this.dashboardService.setAutoScan(true).subscribe(
      response => {
        // alert = $translate.instant(
        //   "dashboard.body.message.AUTO_SCAN_ENABLE_OK"
        // );
        // Alertify.set({ delay: ALERTIFY_SUCCEED_DELAY });
        // Alertify.success(alert);
        this.dashboardDetailsService.isAutoScanOn = true;
      },
      error => {
        if (MapConstant.USER_TIMEOUT.indexOf(error.status) < 0) {
          console.log(error.data);
          // alert = $translate.instant(
          //   "dashboard.body.message.AUTO_SCAN_ENABLE_NG"
          // );
          // Alertify.set({ delay: ALERTIFY_ERROR_DELAY });
          // Alertify.error(Utils.getAlertifyMsg(error, alert, false));
          setTimeout(() => {
            this.isAutoScanOn = false;
          }, 2000);
        }
      }
    );
  };
}
